Java Programming Height & Weight Statistics

This programming assignment is designed to evaluate your knowledge, comprehension and application of some Java programming constructs - floating point, expressions, conditionals, loops, string manipulation, formatted output. It is expected that a program can be written that compiles and runs correctly. You should work on this programming assignment on your own. However, collaboration with others on general logic flow, techniques and Java Core API methods available may be useful. It is most beneficial if you do not share code.

Assignment: After an intensive study, Professor Ichbin Dumm of the Department of Studentometrics has revealed that students at the University of Florida typically can be found to be a number of inches tall, and to weigh something. In order to be able to support his revolutionary thesis with some hard, empirical evidence, though, he has hired you, a world-renowned Java expert and keypunching maven, to design a program which will analyze data on student heights and weights. (To provide data for you program, he has kidnapped a number of students (he will not tell you how many), and induced them to divulge their vital statistics by torturing them with endless reruns of "Sheriff Lobo."). These statistics are recorded in a data file in the following order: sex of student #1 (M|m=male, F|f=female), height of student #1, weight of student #1, sex, height, weight of student #2, etc… Each piece of data is in text format on a separate line. The end of the file is detected when the end-of-file marker is encountered. This is indicated in the Java file readLine() method by returning a null reference (not the same as the empty string "") to the String variable.

Sample data file input text values:

F
60
100
m
80
190
f
65
95
f
71
132
M
68
145

Program: What the professor needs is for you to write a Java program that reads input from a data file (you can assume the data is valid, non-negative and the greatest height and weight is under 2000) and display the average, greatest and least height and weight for male, female and all students. Average in this case means the arithmetic mean. Some other information of interest is to also be displayed. The output should be displayed on the screen as in the sample output below. Note that the input will be in integer numbers for the height and weight however the output for the average height and weight should be in real numbers. The real number output should be no more than to two decimal places, you can ignore the need to round to those two decimal places.

Sample screen output during a particular running of the program:

			Men		Women		All Students
Average Height          71.66		65.2		68.43
Greatest Height		82		74		82
Least Height		48		53		48

Average Weight		180.01		110.0		139.89
Greatest Weight		240		150		240
Least Weight		135		85		85

The number of male students in the study is 48.
The number of female students in the study is 51.

 

The name of the object must be Ex4. To run the program, the Ex4 Java object is invoked. The Ex4 skeleton source code is presented below and should be used. This source code should be put in a file named Ex4.java and then compiled. When it is compiled the object that is run will be called Ex4.class.

IMPORTANT: The file for this program must be named Ex4.java. (Not EX04, ex4, or any other variation). Your file must be should placed in a subdirectory for this project. I suggest something like C:\javacode\Ex4\

 

Ex4.java code:

import java.io.*;

public class Ex4
{
   
      public Ex4()
      {
      }
   
      static BufferedReader fileIn;
   
      static String readDatum()
      {
         String datumRead = "";
      
         try
         {
            datumRead = fileIn.readLine();
         }
            catch (IOException e)
            {
            }
         return datumRead;
      }
   
      public static void main(String[] args)
      {
	 String dataIn = "";

	   //insert variable declaration and initialization

         try
         {
            fileIn = new BufferedReader(new FileReader("Ex4.txt"));
         }
            catch (FileNotFoundException e)
            {
               System.out.println("ERROR: "+e.getMessage());
               System.exit(1);
            }
      
         while ( (dataIn=readDatum()) != null )
         {
		//insert logic to process input
         }
      
	   //insert logic to display information

         try
         {
            fileIn.close();
         }
            catch (IOException e)
            {
            }
      
      } //end main
   
   } //end class Ex4